.TH std::filesystem::path 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::filesystem::path \- std::filesystem::path

.SH Synopsis
   Defined in header <filesystem>
   class path;                     \fI(since C++17)\fP

   Objects of type path represent paths on a filesystem. Only syntactic aspects of
   paths are handled: the pathname may represent a non-existing path or even one that
   is not allowed to exist on the current file system or OS.

   The path name has the following syntax:

    1. root-name(optional): identifies the root on a filesystem with multiple roots
       (such as "C:" or "//myserver"). In case of ambiguity, the longest sequence of
       characters that forms a valid root-name is treated as the root-name. The
       standard library may define additional root-names besides the ones understood by
       the OS API.
    2. root-directory(optional): a directory separator that, if present, marks this
       path as absolute. If it is missing (and the first element other than the root
       name is a file name), then the path is relative and requires another path as the
       starting location to resolve to a file name.
    3. Zero or more of the following:

     * file-name: sequence of characters that aren't directory separators or preferred
       directory separators (additional limitations may be imposed by the OS or file
       system). This name may identify a file, a hard link, a symbolic link, or a
       directory. Two special file-names are recognized:

     * dot: the file name consisting of a single dot character . is a directory name
       that refers to the current directory.
     * dot-dot: the file name consisting of two dot characters .. is a directory name
       that refers to the parent directory.
     * directory-separators: the forward slash character / or the alternative character
       provided as path::preferred_separator. If this character is repeated, it is
       treated as a single directory separator: /usr///////lib is the same as /usr/lib.

   A path can be normalized by following this algorithm:

    1. If the path is empty, stop (normal form of an empty path is an empty path).
    2. Replace each directory-separator (which may consist of multiple slashes) with a
       single path::preferred_separator.
    3. Replace each slash character in the root-name with path::preferred_separator.
    4. Remove each dot and any immediately following directory-separator.
    5. Remove each non-dot-dot filename immediately followed by a directory-separator
       and a dot-dot, along with any immediately following directory-separator.
    6. If there is root-directory, remove all dot-dots and any directory-separators
       immediately following them.
    7. If the last filename is dot-dot, remove any trailing directory-separator.
    8. If the path is empty, add a dot (normal form of ./ is .).

   The path can be traversed element-wise via iterators returned by the begin() and
   end() functions, which views the path in generic format and iterates over root name,
   root directory, and the subsequent file name elements (directory separators are
   skipped except the one that identifies the root directory). If the very last element
   in the path is a directory separator, the last iterator will dereference to an empty
   element.

   Calling any non-const member function of a path invalidates all iterators referring
   to elements of that object.

   If the OS uses a native syntax that is different from the portable generic syntax
   described above, library functions that are defined to accept "detected format"
   accept path names in both formats: a detected format argument is taken to be in the
   generic format if and only if it matches the generic format but is not acceptable to
   the operating system as a native path. On those OS where native format differs
   between pathnames of directories and pathnames of files, a generic pathname is
   treated as a directory path if it ends on a directory separator and a regular file
   otherwise.

   In any case, the path class behaves as if it stores a pathname in the native format
   and automatically converts to generic format as needed (each member function
   specifies which format it interprets the path as).

   On POSIX systems, the generic format is the native format and there is no need to
   distinguish or convert between them.

   Paths are implicitly convertible to and from std::basic_strings, which makes it
   possible to use them with other file APIs.

   The stream operators use std::quoted so that spaces do not cause truncation when
   later read by stream input operator.

   Decomposition member functions (e.g. extension) return filesystem::path objects
   instead of string objects as other APIs do.

.SH Member types and constants

   Type           Definition
   value_type     character type used by the native encoding of the filesystem: char on
                  POSIX, wchar_t on Windows
   string_type    std::basic_string<value_type>
                  a constant LegacyInputIterator with a value_type of path that meets
                  all requirements of LegacyBidirectionalIterator except that for two
                  equal dereferenceable iterators a and b of type const_iterator, there
   const_iterator is no requirement that *a and *b refer to the same object.

                  It is unspecified whether const_iterator is actually a
                  LegacyBidirectionalIterator
   iterator       an alias to const_iterator
                  determines how to interpret string representations of pathnames.

                  The following enumerators are also defined:

   format         Constant       Explanation
   \fI(C++17)\fP        native_format  native pathname format
                  generic_format generic pathname format
                  auto_format    implementation-defined format, auto-detected where
                                 possible

                  \fI(enum)\fP

.SH Member constants

                        alternative directory separator which may be used in addition
   constexpr value_type to the portable /. On Windows, this is the backslash character
   preferred_separator  \\. On POSIX, this is the same forward slash / as the portable
   \fB[static]\fP             separator
                        \fI(public static member constant)\fP

.SH Member functions

   constructor          constructs a path
                        \fI(public member function)\fP
   destructor           destroys a path object
                        \fI(public member function)\fP
   operator=            assigns another path
                        \fI(public member function)\fP
   assign               assigns contents
                        \fI(public member function)\fP
         Concatenation
   append               appends elements to the path with a directory separator
   operator/=           \fI(public member function)\fP
   concat               concatenates two paths without introducing a directory
   operator+=           separator
                        \fI(public member function)\fP
.SH Modifiers
   clear                erases the contents
                        \fI(public member function)\fP
   make_preferred       converts directory separators to preferred directory separator
                        \fI(public member function)\fP
   remove_filename      removes filename path component
                        \fI(public member function)\fP
   replace_filename     replaces the last path component with another path
                        \fI(public member function)\fP
   replace_extension    replaces the extension
                        \fI(public member function)\fP
   swap                 swaps two paths
                        \fI(public member function)\fP
         Format observers
   c_str                returns the native version of the path
   native               \fI(public member function)\fP
   operator string_type
   string
   wstring              returns the path in native pathname format converted to a
   u8string             string
   u16string            \fI(public member function)\fP
   u32string
   generic_string
   generic_wstring      returns the path in generic pathname format converted to a
   generic_u8string     string
   generic_u16string    \fI(public member function)\fP
   generic_u32string
         Compare
                        compares the lexical representations of two paths
   compare              lexicographically
                        \fI(public member function)\fP
.SH Generation
   lexically_normal     converts path to normal form
   lexically_relative   converts path to relative form
   lexically_proximate  converts path to proximate form
                        \fI(public member function)\fP
         Decomposition
   root_name            returns the root-name of the path, if present
                        \fI(public member function)\fP
   root_directory       returns the root directory of the path, if present
                        \fI(public member function)\fP
   root_path            returns the root path of the path, if present
                        \fI(public member function)\fP
   relative_path        returns path relative to the root path
                        \fI(public member function)\fP
   parent_path          returns the path of the parent path
                        \fI(public member function)\fP
   filename             returns the filename path component
                        \fI(public member function)\fP
                        returns the stem path component (filename without the final
   stem                 extension)
                        \fI(public member function)\fP
   extension            returns the file extension path component
                        \fI(public member function)\fP
         Queries
   empty                checks if the path is empty
                        \fI(public member function)\fP
   has_root_path
   has_root_name
   has_root_directory
   has_relative_path    checks if the corresponding path element is not empty
   has_parent_path      \fI(public member function)\fP
   has_filename
   has_stem
   has_extension
   is_absolute          checks if root_path() uniquely identifies file system location
   is_relative          \fI(public member function)\fP
.SH Iterators
   begin                iterator access to the path as a sequence of elements
   end                  \fI(public member function)\fP

.SH Non-member functions

   Defined in namespace std::filesystem
   swap(std::filesystem::path)  swaps two paths
   \fI(C++17)\fP                      \fI(function)\fP
   hash_value                   calculates a hash value for a path object
   \fI(C++17)\fP                      \fI(function)\fP
   operator==
   operator!=
   operator<
   operator<=
   operator>
   operator>=
   operator<=>                  lexicographically compares two paths
   \fI(C++17)\fP                      \fI(function)\fP
   \fI(C++17)\fP\fI(until C++20)\fP
   \fI(C++17)\fP\fI(until C++20)\fP
   \fI(C++17)\fP\fI(until C++20)\fP
   \fI(C++17)\fP\fI(until C++20)\fP
   \fI(C++17)\fP\fI(until C++20)\fP
   (C++20)
   operator/                    concatenates two paths with a directory separator
   \fI(C++17)\fP                      \fI(function)\fP
   operator<<                   performs stream input and output on a quoted path
   operator>>                   \fI(function)\fP
   \fI(C++17)\fP
   u8path                       creates a path from a UTF-8 encoded source
   \fI(C++17)\fP(deprecated in C++20) \fI(function)\fP

.SH Helper classes

   Defined in namespace std
   std::hash<std::filesystem::path>      hash support for std::filesystem::path
   \fI(C++17)\fP                               \fI(class template specialization)\fP
   std::formatter<std::filesystem::path> formatting support for filesystem::path
   (C++26)                               \fI(class template specialization)\fP

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to   Behavior as published    Correct behavior
   LWG 3657 C++17      hash for path was disabled enabled
